package com.dhcc.DRGsHosp.application.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import org.dayatang.domain.EntityRepository;
import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.JdbcTemplateObj;
import org.dayatang.querychannel.QueryChannelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.dhcc.DRGsHosp.application.FileUploadApplication;
import com.dhcc.DRGsHosp.application.SumExpenseApplication;
import com.dhcc.DRGsHosp.core.domain.MrAppendPage;
import com.dhcc.DRGsHosp.core.domain.MrBaseInfo;
import com.dhcc.DRGsHosp.core.domain.MrDiagnose;
import com.dhcc.DRGsHosp.core.domain.MrExpense;
import com.dhcc.DRGsHosp.core.domain.MrExpenseSum;
import com.dhcc.DRGsHosp.core.domain.MrIpInfo;
import com.dhcc.DRGsHosp.core.domain.MrOperation;

@Named("drgsHospFileUploadApplicationImplqiaoyilong20190129")
@Transactional
public class FileUploadApplicationImpl implements FileUploadApplication {
	private static final Logger logger = LoggerFactory.getLogger(FileUploadApplicationImpl.class);

	@Autowired
	private SumExpenseApplication sumExpenseApplication;

	@Inject
	private JdbcTemplateObj jdbcTemplateObj;
	private QueryChannelService queryChannel;
	private QueryChannelService getQueryChannelService(){
       if(queryChannel==null){
          queryChannel = InstanceFactory.getInstance(QueryChannelService.class,"queryChannel");
       }
     return queryChannel;
    }
	private EntityRepository repository;
	private EntityRepository getRepository() {
		if (repository == null) {
			repository = InstanceFactory.getInstance(EntityRepository.class, "repository");
		}
		return repository;
	}
	/**  
	 *  @Description：
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#deleteCaseInfo(java.util.List)  
	 */
	@Override
	public String deleteCaseInfo(List<String> idList) {
		Connection connection = null;
		try {  
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sqlIp = " DELETE FROM DRGS.MR_IPINFO WHERE PMAININDEX=? \n";//删除住院信息表
			String sqlAppend = " DELETE FROM DRGS.MR_APPENDPAGE WHERE PMAININDEX=? \n";//删除附页信息表
			String sqlDiag = " DELETE FROM DRGS.MR_DIAGNOSE WHERE PMAININDEX=? \n";//删除诊断信息表
			String sqlOper = " DELETE FROM DRGS.MR_OPERATION WHERE PMAININDEX=? \n";//删除手术信息表
			String sqlExp = " DELETE FROM DRGS.MR_EXPENSE WHERE PMAININDEX=? \n";//删除费用信息表
			String sqlExps = " DELETE FROM DRGS.MR_EXPENSE_SUM WHERE PMAININDEX=? \n";//删除费用大类信息表  
			String sqlPatientDrg = " DELETE FROM DRGS.T_PATIENTDRG WHERE PARID=? \n";//删除分组信息表  
			String sqlGrouplog = " DELETE FROM DRGS.T_GROUPINGLOG WHERE MR_ADM=? \n";//删除分组日志信息表  
			String sqlOtheorlog = " DELETE FROM DRGS.T_OTHER_GROUPINGRESULT WHERE MR_ID=? \n";//删除其他分组日志表
			String sqlBase = " DELETE FROM DRGS.MR_BASEINFO WHERE PMAININDEX=? \n";//删除基本信息表 最后删除 要不违反外键约束
		    connection.setAutoCommit(false);//设置不自动提交
		    PreparedStatement psIp=connection.prepareStatement(sqlIp);  
		    for (String id : idList) {  
		    	psIp.setString(1, id); 
		    	psIp.addBatch();  
		    }  
		    psIp.executeBatch(); 
		    PreparedStatement psAppend=connection.prepareStatement(sqlAppend);  
		    for (String id : idList) {  
		    	psAppend.setString(1, id); 
		    	psAppend.addBatch();  
		    }  
		    psAppend.executeBatch(); 
		    PreparedStatement psDiag=connection.prepareStatement(sqlDiag);  
		    for (String id : idList) {  
		    	psDiag.setString(1, id); 
		    	psDiag.addBatch();  
		    }  
		    psDiag.executeBatch(); 
		    PreparedStatement psOper=connection.prepareStatement(sqlOper);  
		    for (String id : idList) {  
		    	psOper.setString(1, id); 
		    	psOper.addBatch();  
		    }  
		    psOper.executeBatch(); 
		    PreparedStatement psExp=connection.prepareStatement(sqlExp);  
		    for (String id : idList) {  
		    	psExp.setString(1, id); 
		    	psExp.addBatch();  
		    }  
		    psExp.executeBatch(); 
		    PreparedStatement psExps=connection.prepareStatement(sqlExps);  
		    for (String id : idList) {  
		    	psExps.setString(1, id); 
		    	psExps.addBatch();  
		    }  
		    psExps.executeBatch(); 
		    PreparedStatement psPd=connection.prepareStatement(sqlPatientDrg);  
		    for (String id : idList) {  
		    	psPd.setString(1, id); 
		    	psPd.addBatch();  
		    }  
		    psPd.executeBatch(); 
		    PreparedStatement psGl=connection.prepareStatement(sqlGrouplog);  
		    for (String id : idList) {  
		    	psGl.setString(1, id); 
		    	psGl.addBatch();  
		    }  
		    psGl.executeBatch(); 
		    PreparedStatement psOtherGl=connection.prepareStatement(sqlOtheorlog);  
		    for (String id : idList) {  
		    	psOtherGl.setString(1, id); 
		    	psOtherGl.addBatch();  
		    }  
		    psOtherGl.executeBatch(); 
		    //最后删除基本信息要不违反外键约束
		    PreparedStatement psBase=connection.prepareStatement(sqlBase);  
		    for (String id : idList) {  
		    	psBase.setString(1, id); 
		    	psBase.addBatch();  
		    }  
		    psBase.executeBatch();
		    connection.commit();//提交事务  
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("delete");
		}catch (SQLException e) { 
			logger.error(e.getMessage());
			e.printStackTrace();
			return e.getMessage();
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return "success";
	}
	/**  
	 *  @Description：保存基本信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveBaseInfo(java.util.List)  
	 */
	@Override
	public void saveBaseInfo(List<MrBaseInfo> baseList) {
		Connection connection = null;
		try {
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sql = "INSERT INTO DRGS.MR_BASEINFO(PMAININDEX,P00010000,P00010001,P00020000,P00020001,P00030000,P00040000,P00050000,"
			+"P00060000,P00070000,P00070001,P00080000,P00090000,P00100000,P00110000,P00120000,P00130000,P00130100,P00130200,P00130300,"
			+"P00140000,P00140100,P00140200,P00150000,P00160000,P00170000,P00180000,P00190000,P00190100,P00190200,P00190300,P00190400,"
			+"P00190500,P00190600,P00200000,P00200100,P00200200,P00200300,P00200400,P00200500,P00210000,P00210100,P00210200,P00220000,"
			+"P00220100,P00220200,P00220300,P00090001,P00090002,P00220400,PUSH_DATE) VALUES "
			+"(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";//保存基本信息表
			
		    connection.setAutoCommit(false);//设置不自动提交
		    
		    PreparedStatement psBase=connection.prepareStatement(sql);  
		    for (MrBaseInfo base : baseList) {  
		    	psBase.setString(1,base.getPmainIndex());
		    	psBase.setString(2,base.getP00010000());
		    	psBase.setString(3,base.getP00010001());
		    	psBase.setString(4,base.getP00020000());
		    	psBase.setString(5,base.getP00020001());
		    	psBase.setString(6,base.getP00030000());
		    	if(base.getP00040000()==null)
		    	{
		    		psBase.setNull(7,Types.BIT);
		    	}
		    	else
		    	{
		    		psBase.setInt(7,base.getP00040000());
		    	}
		    	psBase.setString(8,base.getP00050000());
		    	psBase.setString(9,base.getP00060000());
		    	psBase.setString(10,base.getP00070000());
		    	psBase.setString(11,base.getP00070001());
		    	
		    	if(base.getP00080000()==null)
		    	{
		    		psBase.setNull(12,Types.DATE);
		    	}
		    	else
		    	{
		    		psBase.setTimestamp(12,new java.sql.Timestamp(base.getP00080000().getTime()));
		    	}
		    	if(base.getP00090000()==null)
		    	{
		    		psBase.setNull(13,Types.BIT);
		    	}
		    	else
		    	{
		    		psBase.setInt(13,base.getP00090000());
		    	}
		    	psBase.setString(14,base.getP00100000());
		    	if(base.getP00110000()==null)
		    	{
		    		psBase.setNull(15,Types.BIT);
		    	}
		    	else
		    	{
		    		psBase.setInt(15,base.getP00110000());
		    	}
		    	if(base.getP00120000()==null)
		    	{
		    		psBase.setNull(16,Types.BIT);
		    	}
		    	else
		    	{
		    		psBase.setInt(16,base.getP00120000());
		    	}
		    	psBase.setString(17,base.getP00130000());
		    	psBase.setString(18,base.getP00130100());
		    	psBase.setString(19,base.getP00130200());
		    	psBase.setString(20,base.getP00130300());
		    	psBase.setString(21,base.getP00140000());
		    	psBase.setString(22,base.getP00140100());
		    	psBase.setString(23,base.getP00140200());
		    	psBase.setString(24,base.getP00150000());
		    	psBase.setString(25,base.getP00160000());
		    	psBase.setString(26,base.getP00170000());
		    	psBase.setString(27,base.getP00180000());
		    	psBase.setString(28,base.getP00190000());
		    	psBase.setString(29,base.getP00190100());
		    	psBase.setString(30,base.getP00190200());
		    	psBase.setString(31,base.getP00190300());
		    	psBase.setString(32,base.getP00190400());
		    	psBase.setString(33,base.getP00190500());
		    	psBase.setString(34,base.getP00190600());
		    	psBase.setString(35,base.getP00200000());
		    	psBase.setString(36,base.getP00200100());
		    	psBase.setString(37,base.getP00200200());
		    	psBase.setString(38,base.getP00200300());
		    	psBase.setString(39,base.getP00200400());
		    	psBase.setString(40,base.getP00200500());
		    	psBase.setString(41,base.getP00210000());
		    	psBase.setString(42,base.getP00210100());
		    	psBase.setString(43,base.getP00210200());
		    	psBase.setString(44,base.getP00220000());
		    	psBase.setString(45,base.getP00220100());
		    	psBase.setString(46,base.getP00220200());
		    	psBase.setString(47,base.getP00220300());
		    	if(base.getP00090001()==null)
		    	{
		    		psBase.setNull(48,Types.BIT);
		    	}
		    	else
		    	{
		    		psBase.setInt(48,base.getP00090001());
		    	}
		    	if(base.getP00090002()==null)
		    	{
		    		psBase.setNull(49,Types.BIT);
		    	}
		    	else
		    	{
		    		psBase.setInt(49,base.getP00090002());
		    	}
		    	psBase.setString(50,base.getP00220400());
		    	psBase.setTimestamp(51,new java.sql.Timestamp(System.currentTimeMillis()));
		    	psBase.addBatch();  
		    }  
		    psBase.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("base");
		}catch (SQLException e) {  
			logger.error(e.getMessage());
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**  
	 *  @Description：保存住院信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveIpInfo(java.util.List)  
	 */
	@Override
	public void saveIpInfo(List<MrIpInfo> ipList) {
		Connection connection = null;
		try {
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sql = "INSERT INTO DRGS.MR_IPINFO(PMAININDEX,P00230000,P00230001,P00240000,P00240001,P00250000,P00250100,P00260000,P00260001,"
			+"P00270000,P00270001,P00280000,P00280001,P00290000,P00290100,P00300000,P00300001,P00310000,P00310001,P00320000,P00330000,P00330001,"
			+"P00340000,P00350000,P00360000,P00370000,P00380000,P00380001,P00390000,P00400100,P00400200,P00400300,P00410000,P00410001,P00420000,"
			+"P00420001,P00430000,P00430001,P00440000,P00440001,P00450000,P00450001,P00460000,P00460001,P00470000,P00470001,P00480000,P00480001,"
			+"P00490000,P00500000,P00510000,P00520000,P00530000,P00540000,P00550000,P00550101,P00550102,P00550103,P00560000,P00570000,P00570001,"
			+"P00580000,P00580001,P00590000,P00590100,P00590200,P00590300,P00590400,P00590500,P00600100,P00600101,P00600200,P00600201,P00600300,"
			+"P00600301,P00600400,P00600401,P00600500,P00600600,P00600700,P00600800,P00600900,P00610000,P00610001,P00610100,P00610200,P00610300,"
			+"P00620000,P00620001,P00620100,P00620200,P00630000,P00630001,P00630100,P00640001,P00640002,P00640003,P00650001,P00650002,P00650003,"
			+"P00700000,P00800000,P00810000,P00900000,P00400101,P00400201,P00400301,P00910000,P00920000,P00930000,P00930001,P00930002,P00940001,"
			+"P00940002,P00601000,P00601001,P00950000,P00950001,P00950002,P00960000,P00960001,P00400401,P00900001) VALUES (?,?,?,?,?,?,?,?,?,?,?,"
			+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
			+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";;//保存住院信息表
		    connection.setAutoCommit(false);//设置不自动提交
		    
		    PreparedStatement psIp=connection.prepareStatement(sql);  
		    for (MrIpInfo ip : ipList) {
		    	psIp.setString(1,ip.getPmainIndex());
		    	psIp.setString(2,ip.getP00230000());
		    	psIp.setString(3,ip.getP00230001());
		    	psIp.setString(4,ip.getP00240000());
		    	psIp.setString(5,ip.getP00240001());
		    	if(ip.getP00250000()==null)
		    	{
		    		psIp.setNull(6,Types.DATE);
		    	}
		    	else
		    	{
		    		
		    		psIp.setTimestamp(6,new java.sql.Timestamp(ip.getP00250000().getTime()));
		    	}
		    	psIp.setString(7,ip.getP00250100());
		    	psIp.setString(8,ip.getP00260000());
		    	psIp.setString(9,ip.getP00260001());
		    	psIp.setString(10,ip.getP00270000());
		    	psIp.setString(11,ip.getP00270001());
		    	psIp.setString(12,ip.getP00280000());
		    	psIp.setString(13,ip.getP00280001());
		    	if(ip.getP00290000()==null)
		    	{
		    		psIp.setNull(14,Types.DATE);
		    	}
		    	else
		    	{
		    		psIp.setTimestamp(14,new java.sql.Timestamp(ip.getP00290000().getTime()));
		    	}
		    	psIp.setString(15,ip.getP00290100());
		    	psIp.setString(16,ip.getP00300000());
		    	psIp.setString(17,ip.getP00300001());
		    	psIp.setString(18,ip.getP00310000());
		    	psIp.setString(19,ip.getP00310001());
		    	if(ip.getP00320000()==null)
		    	{
		    		psIp.setNull(20,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(20,ip.getP00320000());
		    	}
		    	psIp.setString(21,ip.getP00330000());
		    	psIp.setString(22,ip.getP00330001());
		    	psIp.setString(23,ip.getP00340000());
		    	psIp.setString(24,ip.getP00350000());
		    	psIp.setString(25,ip.getP00360000());
		    	psIp.setString(26,ip.getP00370000());
		    	psIp.setString(27,ip.getP00380000());
		    	psIp.setString(28,ip.getP00380001());
		    	if(ip.getP00390000()==null)
		    	{
		    		psIp.setNull(29,Types.DATE);
		    	}
		    	else
		    	{
		    		psIp.setTimestamp(29,new java.sql.Timestamp(ip.getP00390000().getTime()));
		    	}
		    	psIp.setString(30,ip.getP00400100());
		    	psIp.setString(31,ip.getP00400200());
		    	psIp.setString(32,ip.getP00400300());
		    	psIp.setString(33,ip.getP00410000());
		    	psIp.setString(34,ip.getP00410001());
		    	psIp.setString(35,ip.getP00420000());
		    	psIp.setString(36,ip.getP00420001());
		    	psIp.setString(37,ip.getP00430000());
		    	psIp.setString(38,ip.getP00430001());
		    	psIp.setString(39,ip.getP00440000());
		    	psIp.setString(40,ip.getP00440001());
		    	psIp.setString(41,ip.getP00450000());
		    	psIp.setString(42,ip.getP00450001());
		    	psIp.setString(43,ip.getP00460000());
		    	psIp.setString(44,ip.getP00460001());
		    	psIp.setString(45,ip.getP00470000());
		    	psIp.setString(46,ip.getP00470001());
		    	psIp.setString(47,ip.getP00480000());
		    	psIp.setString(48,ip.getP00480001());
		    	if(ip.getP00490000()==null)
		    	{
		    		psIp.setNull(49,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(49,ip.getP00490000());
		    	}
		    	if(ip.getP00500000()==null)
		    	{
		    		psIp.setNull(50,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(50,ip.getP00500000());
		    	}
		    	psIp.setString(51,ip.getP00510000());
		    	psIp.setString(52,ip.getP00520000());
		    	psIp.setString(53,ip.getP00530000());
		    	psIp.setString(54,ip.getP00540000());
		    	psIp.setString(55,ip.getP00550000());
		    	if(ip.getP00550101()==null)
		    	{
		    		psIp.setNull(56,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(56,ip.getP00550101());
		    	}
		    	if(ip.getP00550102()==null)
		    	{
		    		psIp.setNull(57,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(57,ip.getP00550102());
		    	}
		    	if(ip.getP00550103()==null)
		    	{
		    		psIp.setNull(58,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(58,ip.getP00550103());
		    	}
		    	psIp.setString(59,ip.getP00560000());
		    	psIp.setString(60,ip.getP00570000());
		    	psIp.setString(61,ip.getP00570001());
		    	psIp.setString(62,ip.getP00580000());
		    	psIp.setString(63,ip.getP00580001());
		    	psIp.setString(64,ip.getP00590000());
		    	if(ip.getP00590100()==null)
		    	{
		    		psIp.setNull(65,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psIp.setDouble(65,ip.getP00590100());
		    	}
		    	if(ip.getP00590200()==null)
		    	{
		    		psIp.setNull(66,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psIp.setDouble(66,ip.getP00590200());
		    	}
		    	if(ip.getP00590300()==null)
		    	{
		    		psIp.setNull(67,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psIp.setDouble(67,ip.getP00590300());
		    	}
		    	if(ip.getP00590400()==null)
		    	{
		    		psIp.setNull(68,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psIp.setDouble(68,ip.getP00590400());
		    	}
		    	if(ip.getP00590500()==null)
		    	{
		    		psIp.setNull(69,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psIp.setDouble(69,ip.getP00590500());
		    	}
		    	psIp.setString(70,ip.getP00600100());
		    	psIp.setString(71,ip.getP00600101());
		    	psIp.setString(72,ip.getP00600200());
		    	psIp.setString(73,ip.getP00600201());
		    	psIp.setString(74,ip.getP00600300());
		    	psIp.setString(75,ip.getP00600301());
		    	psIp.setString(76,ip.getP00600400());
		    	psIp.setString(77,ip.getP00600401());
		    	psIp.setString(78,ip.getP00600500());
		    	psIp.setString(79,ip.getP00600600());
		    	psIp.setString(80,ip.getP00600700());
		    	psIp.setString(81,ip.getP00600800());
		    	psIp.setString(82,ip.getP00600900());
		    	psIp.setString(83,ip.getP00610000());
		    	psIp.setString(84,ip.getP00610001());
		    	psIp.setString(85,ip.getP00610100());
		    	psIp.setString(86,ip.getP00610200());
		    	if(ip.getP00610300()==null)
		    	{
		    		psIp.setNull(87,Types.DATE);
		    	}
		    	else
		    	{
		    		psIp.setTimestamp(87,new java.sql.Timestamp(ip.getP00610300().getTime()));
		    	}
		    	psIp.setString(88,ip.getP00620000());
		    	psIp.setString(89,ip.getP00620001());
		    	psIp.setString(90,ip.getP00620100());
		    	psIp.setString(91,ip.getP00620200());
		    	psIp.setString(92,ip.getP00630000());
		    	psIp.setString(93,ip.getP00630001());
		    	psIp.setString(94,ip.getP00630100());
		    	if(ip.getP00640001()==null)
		    	{
		    		psIp.setNull(95,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(95,ip.getP00640001());
		    	}
		    	if(ip.getP00640002()==null)
		    	{
		    		psIp.setNull(96,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(96,ip.getP00640002());
		    	}
		    	if(ip.getP00640003()==null)
		    	{
		    		psIp.setNull(97,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(97,ip.getP00640003());
		    	}
		    	if(ip.getP00650001()==null)
		    	{
		    		psIp.setNull(98,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(98,ip.getP00650001());
		    	}
		    	if(ip.getP00650002()==null)
		    	{
		    		psIp.setNull(99,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(99,ip.getP00650002());
		    	}
		    	if(ip.getP00650003()==null)
		    	{
		    		psIp.setNull(100,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(100,ip.getP00650003());
		    	}
		    	if(ip.getP00700000()==null)
		    	{
		    		psIp.setNull(101,Types.BIT);
		    	}
		    	else
		    	{
		    		psIp.setInt(101,ip.getP00700000());
		    	}
		    	if(ip.getP00800000()==null)
		    	{
		    		psIp.setNull(102,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psIp.setDouble(102,ip.getP00800000());
		    	}if(ip.getP00810000()==null)
		    	{
		    		psIp.setNull(103,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psIp.setDouble(103,ip.getP00810000());
		    	}
		    	psIp.setString(104,ip.getP00900000());
		    	psIp.setString(105,ip.getP00400101());
		    	psIp.setString(106,ip.getP00400201());
		    	psIp.setString(107,ip.getP00400301());
		    	psIp.setString(108,ip.getP00910000());
		    	psIp.setString(109,ip.getP00920000());
		    	psIp.setString(110,ip.getP00930000());
		    	if(ip.getP00930001()==null)
		    	{
		    		psIp.setNull(111,Types.DATE);
		    	}
		    	else
		    	{
		    		psIp.setTimestamp(111,new java.sql.Timestamp(ip.getP00930001().getTime()));
		    	}
		    	if(ip.getP00930002()==null)
		    	{
		    		psIp.setNull(112,Types.DATE);
		    	}
		    	else
		    	{
		    		psIp.setTimestamp(112,new java.sql.Timestamp(ip.getP00930002().getTime()));
		    	}
		    	psIp.setString(113,ip.getP00940001());
		    	psIp.setString(114,ip.getP00940002());
		    	psIp.setString(115,ip.getP00601000());
		    	psIp.setString(116,ip.getP00601001());
		    	psIp.setString(117,ip.getP00950000());
		    	psIp.setString(118,ip.getP00950001());
		    	psIp.setString(119,ip.getP00950002());
		    	psIp.setString(120,ip.getP00960000());
		    	psIp.setString(121,ip.getP00960001());
		    	psIp.setString(122,ip.getP00400401());
		    	psIp.setString(123,ip.getP00900001());
		    	psIp.addBatch();
		    }  
		    psIp.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("ip");
		}catch (SQLException e) {
			logger.error(e.getMessage());
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	
	}
	/**  
	 *  @Description：保存附页信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveAppInfo(java.util.List)  
	 */
	@Override
	public void saveAppInfo(List<MrAppendPage> appList) {
		Connection connection = null;
		try {
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sql = "INSERT INTO DRGS.MR_APPENDPAGE(PMAININDEX,P90010000,P90010001,P90020000,P90020001,P90031000,P90031001,P90032000,P90041000,P90041001,"
			+"P90042000,P90051000,P90051001,P90052000,P90061000,P90061001,P90062000,P90070000,P90080000,P90080001,P90090000,P90090001,P90100000,P90100001,"
			+"P90110000,P90110001,P90120000,P90120001,P90130000,P90130001,P90140000,P90140001,P90150000,P90150001,P90120201) VALUES "
			+"(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";//保存附页信息表
			
		    connection.setAutoCommit(false);//设置不自动提交
		    
		    PreparedStatement psApp=connection.prepareStatement(sql);  
		    for (MrAppendPage app : appList) {
		    	psApp.setString(1,app.getPmainIndex());
		    	psApp.setString(2,app.getP90010000());
		    	psApp.setString(3,app.getP90010001());
		    	psApp.setString(4,app.getP90020000());
		    	psApp.setString(5,app.getP90020001());
		    	psApp.setString(6,app.getP90031000());
		    	psApp.setString(7,app.getP90031001());
		    	psApp.setString(8,app.getP90032000());
		    	psApp.setString(9,app.getP90041000());
		    	psApp.setString(10,app.getP90041001());
		    	psApp.setString(11,app.getP90042000());
		    	psApp.setString(12,app.getP90051000());
		    	psApp.setString(13,app.getP90051001());
		    	psApp.setString(14,app.getP90052000());
		    	psApp.setString(15,app.getP90061000());
		    	psApp.setString(16,app.getP90061001());
		    	psApp.setString(17,app.getP90062000());
		    	psApp.setString(18,app.getP90070000());
		    	psApp.setString(19,app.getP90080000());
		    	psApp.setString(20,app.getP90080001());
		    	psApp.setString(21,app.getP90090000());
		    	psApp.setString(22,app.getP90090001());
		    	psApp.setString(23,app.getP90100000());
		    	psApp.setString(24,app.getP90100001());
		    	psApp.setString(25,app.getP90110000());
		    	psApp.setString(26,app.getP90110001());
		    	psApp.setString(27,app.getP90120000());
		    	psApp.setString(28,app.getP90120001());
		    	psApp.setString(29,app.getP90130000());
		    	psApp.setString(30,app.getP90130001());
		    	psApp.setString(31,app.getP90140000());
		    	psApp.setString(32,app.getP90140001());
		    	psApp.setString(33,app.getP90150000());
		    	psApp.setString(34,app.getP90150001());
		    	if(app.getP90120201()==null)
		    	{
		    		psApp.setNull(35,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psApp.setDouble(35,app.getP90120201());
		    	}
		    	psApp.addBatch();
		    }  
		    psApp.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("app");
		}catch (SQLException e) {  
			logger.error(e.getMessage());
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**  
	 *  @Description：保存诊断信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveDiagInfo(java.util.List)  
	 */
	@Override
	public void saveDiagInfo(List<MrDiagnose> diagList) {
		Connection connection = null;
		try {
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sql = "INSERT INTO DRGS.MR_DIAGNOSE(PMAININDEX,PD0101,PD0100,PD0201,PD0200,PD0301,PD0300,PDTYPE,PDINDEX,PD0202) VALUES "
			+"(?,?,?,?,?,?,?,?,?,?) ";//保存诊断信息表
			
		    connection.setAutoCommit(false);//设置不自动提交
		    
		    PreparedStatement psDiag=connection.prepareStatement(sql);  
		    for (MrDiagnose diag : diagList) {
		    	psDiag.setString(1,diag.getPmainIndex());
		    	psDiag.setString(2,diag.getPd0101());
		    	psDiag.setString(3,diag.getPd0100());
		    	psDiag.setString(4,diag.getPd0201());
		    	psDiag.setString(5,diag.getPd0200());
		    	psDiag.setString(6,diag.getPd0301());
		    	psDiag.setString(7,diag.getPd0300());
		    	psDiag.setString(8,diag.getPdType());
		    	if(diag.getPdIndex()==null)
		    	{
		    		psDiag.setNull(9,Types.BIT);
		    	}
		    	else
		    	{
		    		psDiag.setInt(9,diag.getPdIndex());
		    	}
		    	psDiag.setString(10,diag.getPd0202());
		    	psDiag.addBatch();
		    }  
		    psDiag.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("diag");
		}catch (SQLException e) {
			logger.error(e.getMessage());
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**  
	 *  @Description：保存手术信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveOperInfo(java.util.List)  
	 */
	@Override
	public void saveOperInfo(List<MrOperation> operList) {
		Connection connection = null;
		try {
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sql = "INSERT INTO DRGS.MR_OPERATION(PMAININDEX, POTYPE, POINDEX, PO0100, PO0101, PO0200, PO0300, PO0301, PO0400, PO0401, PO0500, PO0501, "
			+"PO0600, PO0601, PO0700, PO0701, PO0800, PO0801, PO0900, PO0901, PO1000, PO1001, PO1100, PO1200, PO1201, PO1300, PO1301,PO1400,PO1500,PO1501,PO0201)"
			+"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";//保存手术信息表
			
		    connection.setAutoCommit(false);//设置不自动提交
		    
		    PreparedStatement psOper=connection.prepareStatement(sql);  
		    for (MrOperation oper : operList) {
		    	psOper.setString(1,oper.getPmainIndex());
		    	psOper.setString(2,oper.getPoType());
		    	if(oper.getPoIndex()==null)
		    	{
		    		psOper.setNull(3,Types.BIT);
		    	}
		    	else
		    	{
		    		psOper.setInt(3,oper.getPoIndex());
		    	}
		    	psOper.setString(4,oper.getPo0100());
		    	psOper.setString(5,oper.getPo0101());
		    	if(oper.getPo0200()==null)
		    	{
		    		psOper.setNull(6,Types.DATE);
		    	}
		    	else
		    	{
		    		psOper.setTimestamp(6,new java.sql.Timestamp(oper.getPo0200().getTime()));
		    	}
		    	psOper.setString(7,oper.getPo0300());
		    	psOper.setString(8,oper.getPo0301());
		    	psOper.setString(9,oper.getPo0400());
		    	psOper.setString(10,oper.getPo0401());
		    	psOper.setString(11,oper.getPo0500());
		    	psOper.setString(12,oper.getPo0501());
		    	psOper.setString(13,oper.getPo0600());
		    	psOper.setString(14,oper.getPo0601());
		    	psOper.setString(15,oper.getPo0700());
		    	psOper.setString(16,oper.getPo0701());
		    	psOper.setString(17,oper.getPo0800());
		    	psOper.setString(18,oper.getPo0801());
		    	psOper.setString(19,oper.getPo0900());
		    	psOper.setString(20,oper.getPo0901());
		    	psOper.setString(21,oper.getPo1000());
		    	psOper.setString(22,oper.getPo1001());
		    	if(oper.getPo1100()==null)
		    	{
		    		psOper.setNull(23,Types.BIT);
		    	}
		    	else
		    	{
		    		psOper.setInt(23,oper.getPo1100());
		    	}
		    	psOper.setString(24,oper.getPo1200());
		    	psOper.setString(25,oper.getPo1201());
		    	psOper.setString(26,oper.getPo1300());
		    	psOper.setString(27,oper.getPo1301());
		    	psOper.setString(28,oper.getPo1400());
		    	if(oper.getPo1500()==null)
		    	{
		    		psOper.setNull(29,Types.DATE);
		    	}
		    	else
		    	{
		    		psOper.setTimestamp(29,new java.sql.Timestamp(oper.getPo1500().getTime()));
		    	}
		    	psOper.setString(30,oper.getPo1501());
		    	psOper.setString(31,oper.getPo0201());
		    	psOper.addBatch();
		    }  
		    psOper.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("oper");
		}catch (SQLException e) {  
			logger.error(e.getMessage());
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**  
	 *  @Description：保存费用信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveExpInfo(java.util.List)  
	 */
	@Override
	public void saveExpInfo(List<MrExpense> expList) {
		Connection connection = null;
		try {
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sql = "INSERT INTO DRGS.MR_EXPENSE(PMAININDEX,PE0100,PE0101,PE0200,PEINDEX,PETYPE)"
			+"VALUES (?,?,?,?,?,?) ";//保存费用信息表
			
		    connection.setAutoCommit(false);//设置不自动提交
		    
		    PreparedStatement psExp=connection.prepareStatement(sql);
		    for (MrExpense exp : expList) {
		    	psExp.setString(1,exp.getPmainIndex());
		    	psExp.setString(2,exp.getPe0100());
		    	psExp.setString(3,exp.getPe0101());
		    	if(exp.getPe0200()==null)
		    	{
		    		psExp.setNull(4,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExp.setDouble(4,exp.getPe0200());
		    	}
		    	if(exp.getPeIndex()==null)
		    	{
		    		psExp.setNull(5,Types.BIT);
		    	}
		    	else
		    	{
		    		psExp.setInt(5,exp.getPeIndex());
		    	}
		    	psExp.setString(6,exp.getPeType());
		    	psExp.addBatch();
		    }
		    psExp.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("exp");
		}catch (SQLException e) { 
			logger.error(e.getMessage());
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**  
	 *  @Description：保存费用大类信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveExpSumInfo(java.util.List)  
	 */
	@Override
	public void saveExpSumInfo(List<MrExpenseSum> expSumList) {
		Connection connection = null;
		try {
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sql = "INSERT INTO DRGS.MR_EXPENSE_SUM(PMAININDEX,DRUG_COST,MATER_COST,DRG_MED_COST,DRG_NURS_COST,DRG_TECH_COST,DRG_DRUG_COST,DRG_MANAGE_COST) VALUES"+"(?,?,?,?,?,?,?,?) ";//保存诊断信息表
			
		    connection.setAutoCommit(false);//设置不自动提交
		    
		    PreparedStatement psExpSum=connection.prepareStatement(sql);  
		    for (MrExpenseSum expSum : expSumList) {
		    	psExpSum.setString(1,expSum.getPmainIndex());
		    	if(expSum.getDrugCost()==null)
		    	{
		    		psExpSum.setNull(2,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExpSum.setDouble(2,expSum.getDrugCost());
		    	}
		    	if(expSum.getMaterCost()==null)
		    	{
		    		psExpSum.setNull(3,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExpSum.setDouble(3,expSum.getMaterCost());
		    	}
		    	if(expSum.getDrgMedCost()==null)
		    	{
		    		psExpSum.setNull(4,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExpSum.setDouble(4,expSum.getDrgMedCost());
		    	}
		    	if(expSum.getDrgNursCost()==null)
		    	{
		    		psExpSum.setNull(5,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExpSum.setDouble(5,expSum.getDrgNursCost());
		    	}
		    	if(expSum.getDrgTechCost()==null)
		    	{
		    		psExpSum.setNull(6,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExpSum.setDouble(6,expSum.getDrgTechCost());
		    	}
		    	if(expSum.getDrgDrugCost()==null)
		    	{
		    		psExpSum.setNull(7,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExpSum.setDouble(7,expSum.getDrgDrugCost());
		    	}
		    	if(expSum.getDrgManageCost()==null)
		    	{
		    		psExpSum.setNull(8,Types.DOUBLE);
		    	}
		    	else
		    	{
		    		psExpSum.setDouble(8,expSum.getDrgManageCost());
		    	}
		    	psExpSum.addBatch();
		    }  
		    psExpSum.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		    System.out.println("expsum");
		}catch (SQLException e) {  
			logger.error(e.getMessage());
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**  
	 *  @Description：
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#deleteDiagById(java.lang.String)  
	 */
	@Override
	public void deleteDiagById(String id) {
		Connection connection = null;
		try {  
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sqlDiag = " DELETE FROM DRGS.MR_DIAGNOSE WHERE PMAININDEX=? \n";//删除诊断信息表
		    connection.setAutoCommit(false);//设置不自动提交
		    PreparedStatement psDiag=connection.prepareStatement(sqlDiag);  
		    psDiag.setString(1, id); 
	    	psDiag.addBatch();  
		    psDiag.executeBatch(); 
		    connection.commit();//提交事务 
		    connection.setAutoCommit(true);//设置自动提交
		}catch (SQLException e) {  
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	
		
	}
	/**  
	 *  @Description：
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#deleteOperById(java.lang.String)  
	 */
	@Override
	public void deleteOperById(String id) {
		Connection connection = null;
		try {  
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sqlOper = " DELETE FROM DRGS.MR_OPERATION WHERE PMAININDEX=? \n";//删除手术信息表
		    connection.setAutoCommit(false);//设置不自动提交
		    PreparedStatement psOper=connection.prepareStatement(sqlOper);  
		    psOper.setString(1, id); 
	    	psOper.addBatch();
		    psOper.executeBatch(); 
		    connection.commit();//提交事务  
		    connection.setAutoCommit(true);//设置自动提交
		}catch (SQLException e) {  
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**  
	 *  @Description：
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#deleteExpById(java.lang.String)  
	 */
	@Override
	public void deleteExpById(String id) {
		Connection connection = null;
		try {  
			connection = jdbcTemplateObj.getDataSource().getConnection();
			String sqlExp = " DELETE FROM DRGS.MR_EXPENSE WHERE PMAININDEX=? \n";//删除费用信息表
		    connection.setAutoCommit(false);//设置不自动提交
		    PreparedStatement psExp=connection.prepareStatement(sqlExp);  
		    psExp.setString(1, id); 
	    	psExp.addBatch(); 
		    psExp.executeBatch(); 
		    connection.commit();//提交事务  
		    connection.setAutoCommit(true);//设置自动提交
		}catch (SQLException e) {  
		    e.printStackTrace();  
		}
		finally {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	/**
	 * 
	 *  @Description：根据费用子类更新总费用
	 *  @Author ZouYiyu  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#updateCostAmount(java.lang.String)
	 */
	public void updateCostAmount(String id) {
		// 检查有无总费用，如没有，计算插入
		try{
			StringBuilder sqlString = new StringBuilder(
					"SELECT IP.P00800000 FROM DRGS.MR_IPINFO IP WHERE IP.PMAININDEX='" + id + "' AND IP.P00800000 IS NULL");
			List<String> costAmount = jdbcTemplateObj.queryForList(sqlString.toString(), String.class);
			if (costAmount == null || costAmount.contains(null)) {
				StringBuilder sqlStr = new StringBuilder();
				sqlStr.append("UPDATE DRGS.MR_IPINFO IP SET IP.P00800000= \n");
				sqlStr.append("(SELECT SUM(EX.PE0200) FROM DRGS.MR_EXPENSE EX WHERE EX.PMAININDEX='" + id + "') \n");
				sqlStr.append("WHERE IP.PMAININDEX='" + id + "' ");
				jdbcTemplateObj.execute(sqlStr.toString());
			}
		}catch(Exception e) { 
			e.printStackTrace();
		}
		
	}
	/**  
	 *  @Description：保存基本信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveBaseInfo(com.dhcc.DRGsHosp.core.domain.MrBaseInfo)  
	 */
	@Override
	public void saveBaseInfo(MrBaseInfo baseInfo) {
		baseInfo.save();	
	}
	/**  
	 *  @Description：保存住院信息
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveIpInfo(com.dhcc.DRGsHosp.core.domain.MrIpInfo)  
	 */
	@Override
	public void saveIpInfo(MrIpInfo ip) {
		ip.save();
	}
	/**  
	 *  @Description：保存附页
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveAppendInfo(com.dhcc.DRGsHosp.core.domain.MrAppendPage)  
	 */
	@Override
	public void saveAppendInfo(MrAppendPage append) {
		append.save();
	}
	/**  
	 *  @Description：保存诊断
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveDiagInfo(com.dhcc.DRGsHosp.core.domain.MrDiagnose)  
	 */
	@Override
	public void saveDiagInfo(MrDiagnose diag) {
		diag.save();
	}
	/**  
	 *  @Description：保存手术
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveOperInfo(com.dhcc.DRGsHosp.core.domain.MrOperation)  
	 */
	@Override
	public void saveOperInfo(MrOperation oper) {
		oper.save();
	}
	/**  
	 *  @Description：保存费用
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveExpInfo(com.dhcc.DRGsHosp.core.domain.MrExpense)  
	 */
	@Override
	public void saveExpInfo(MrExpense exp) {
		exp.save();
	}
	/**  
	 *  @Description：保存费用大类
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveExpSumInfo(com.dhcc.DRGsHosp.core.domain.MrExpenseSum)  
	 */
	@Override
	public void saveExpSumInfo(MrExpenseSum expSum) {
		expSum.save();
	}
	
	/**  
	 *  @Description：
	 *  @Author mazhaoyan  
	 *  @see com.dhcc.DRGsHosp.application.FileUploadApplication#saveCaseInfo(java.util.Map)  
	 */
	@SuppressWarnings("unchecked")
	@Override
	public String saveCaseInfo(Map<String, Object> caseMap) {
		String errInfo = "";
		try {
			String pMainIndex = caseMap.get("pMainIndex").toString();
			MrBaseInfo base = (MrBaseInfo) caseMap.get("base");
			MrIpInfo ip = (MrIpInfo) caseMap.get("ip");
			MrAppendPage append = (MrAppendPage) caseMap.get("append");
			List<MrDiagnose> diagList = (List<MrDiagnose>) caseMap.get("diag");
			List<MrOperation> operList = (List<MrOperation>) caseMap.get("oper");
			List<MrExpense> expList = (List<MrExpense>) caseMap.get("exp");
			base.save();
			ip.save();
			append.save();
			int diagCount = getDiagnoseCount(pMainIndex);
			int cDiagCnt = diagList.size();
			if(diagCount>cDiagCnt){//库里的诊断数目比现有数据多 删除原来库里的数据
				clearDiagnose(pMainIndex,cDiagCnt);
			}
			for(int i=0;i<cDiagCnt;i++){
				createMrDiagnose(diagList.get(i));
			}
			int operCount = getOperationCount(pMainIndex);
			int cOperCnt = operList.size();
			if(operCount>cOperCnt){//库里的手术数目比现有数据多 删除原来库里的数据
				clearOperation(pMainIndex,cOperCnt);
			}
			for(int i=0;i<cOperCnt;i++){
				createMrOperation(operList.get(i));
			}
			int expCount = getExpCount(pMainIndex);
			int cExpCnt = expList.size();
			if(expCount>cExpCnt){//库里的费用数目比现有数据多 删除原来库里的数据
				clearMrExpense(pMainIndex,cExpCnt);
			}
			for(int i=0;i<cExpCnt;i++){
				createMrExpense(expList.get(i));
			}

			//保存费用大类（统一走存储过程）
			sumExpenseApplication.sumExpense(pMainIndex);
		} catch (Exception e) {
			errInfo = e.getMessage();
		}
		return errInfo;
	}
	private int getDiagnoseCount(String pMainIndex){
        String sql = "SELECT COUNT(*)  FROM DRGS.MR_DIAGNOSE T WHERE T.PMAININDEX=:pMainIndex";
        int diagCount = Integer.parseInt(getQueryChannelService().createSqlQuery(sql.toString()).addParameter("pMainIndex", pMainIndex).singleResult().toString());
        return diagCount;
    }
	private int getOperationCount(String pMainIndex){
        String sql = "SELECT COUNT(*)  FROM DRGS.MR_OPERATION T WHERE T.PMAININDEX=:pMainIndex";
        int operCount = Integer.parseInt(getQueryChannelService().createSqlQuery(sql.toString()).addParameter("pMainIndex", pMainIndex).singleResult().toString());
        return operCount;
    }
	private int getExpCount(String pMainIndex){
        String sql = "SELECT COUNT(*)  FROM DRGS.MR_EXPENSE T WHERE T.PMAININDEX=:pMainIndex";
        int expCount = Integer.parseInt(getQueryChannelService().createSqlQuery(sql.toString()).addParameter("pMainIndex", pMainIndex).singleResult().toString());
        return expCount;
    }
	
	public  void clearDiagnose(String pMainIndex,int index){
		Map<String,Object> param  = new HashMap<String,Object>();
		param.put("pMainIndex", pMainIndex);
		param.put("index", index);
		String  sql = "DELETE FROM DRGS.MR_DIAGNOSE T WHERE T.PMAININDEX=:pMainIndex AND T.PDINDEX >= :index";
		getRepository().createSqlQuery(sql).setParameters(param).executeUpdate();
    }
	public  void clearOperation(String pMainIndex,int index){
		Map<String,Object> param  = new HashMap<String,Object>();
		param.put("pMainIndex", pMainIndex);
		param.put("index", index);
		String  sql = "DELETE FROM DRGS.MR_OPERATION T WHERE T.PMAININDEX=:pMainIndex AND T.POINDEX >= :index";
		getRepository().createSqlQuery(sql).setParameters(param).executeUpdate();
    }
	private void clearMrExpense(String pMainIndex,int index){
		Map<String,Object> param  = new HashMap<String,Object>();
		param.put("pMainIndex", pMainIndex);
		param.put("index", index);
		String  sql = "DELETE FROM DRGS.MR_EXPENSE T WHERE T.PMAININDEX=:pMainIndex AND T.PDINDEX >= :index";
		getRepository().createSqlQuery(sql).setParameters(param).executeUpdate();
    }
	
	private void createMrDiagnose(MrDiagnose mr){
		Map<String, Object> parameters = new HashMap<>();
		parameters.put("pMainIndex", mr.getPmainIndex());
		parameters.put("pDIndex", mr.getPdIndex());
		String sql = "SELECT 1 FROM DRGS.MR_DIAGNOSE T WHERE T.PMAININDEX=:pMainIndex AND T.PDINDEX=:pDIndex";
		List<Object> list = getRepository().createSqlQuery(sql).setParameters(parameters).list();
		if(list.size()>0){
			if(mr.getPdType()!=null){parameters.put("pDType", mr.getPdType());}
			if(mr.getPd0100()!=null){parameters.put("pD0100", mr.getPd0100());}
			if(mr.getPd0101()!=null){parameters.put("pD0101", mr.getPd0101());}
			if(mr.getPd0200()!=null){parameters.put("pD0200", mr.getPd0200());}
			if(mr.getPd0201()!=null){parameters.put("pD0201", mr.getPd0201());}
			if(mr.getPd0300()!=null){parameters.put("pD0300", mr.getPd0300());}
			if(mr.getPd0301()!=null){parameters.put("pD0301", mr.getPd0301());}
			sql = "UPDATE DRGS.MR_DIAGNOSE T SET "
			+ (mr.getPdType()!=null?("T.PDTYPE=:pDType, "):("T.PDTYPE = null,  "))
			+ (mr.getPd0100()!=null?("T.PD0100=:pD0100, "):("T.PD0100 = null,  "))
			+ (mr.getPd0101()!=null?("T.PD0101=:pD0101, "):("T.PD0101 = null,  "))
			+ (mr.getPd0200()!=null?("T.PD0200=:pD0200, "):("T.PD0200 = null,  "))
			+ (mr.getPd0201()!=null?("T.PD0201=:pD0201, "):("T.PD0201 = null,  "))
			+ (mr.getPd0300()!=null?("T.PD0300=:pD0300, "):("T.PD0300 = null,  "))
			+ (mr.getPd0301()!=null?("T.PD0301=:pD0301 "):("T.PD0301 = null  "))
			+ "WHERE T.PMAININDEX=:pMainIndex AND T.PDINDEX=:pDIndex";
			if(mr.getPd0101()!=null) {
				getRepository().createSqlQuery(sql).setParameters(parameters).executeUpdate();
			}
		}else{
			if(mr.getPd0101()!=null) {
				mr.save();
			}
		}
	}
	public void createMrOperation(MrOperation mr){
		Map<String, Object> parameters = new HashMap<>();
		parameters.put("pMainIndex", mr.getPmainIndex());
		parameters.put("pOIndex", mr.getPoIndex());
		
		String sql = "SELECT 1 FROM DRGS.MR_OPERATION T WHERE T.PMAININDEX=:pMainIndex AND T.POINDEX=:pOIndex";
		List<Object> list = getRepository().createSqlQuery(sql).setParameters(parameters).list();
		if(list.size()>0){
			if(mr.getPoType()!=null){parameters.put("pOType", mr.getPoType());}
			if(mr.getPo0100()!=null){parameters.put("pO0100", mr.getPo0100());}
			if(mr.getPo0101()!=null){parameters.put("pO0101", mr.getPo0101());}
			if(mr.getPo0200()!=null){parameters.put("pO0200", mr.getPo0200());}
			if(mr.getPo0300()!=null){parameters.put("pO0300", mr.getPo0300());}
			if(mr.getPo0301()!=null){parameters.put("pO0301", mr.getPo0301());}
			if(mr.getPo0400()!=null){parameters.put("pO0400", mr.getPo0400());}
			if(mr.getPo0401()!=null){parameters.put("pO0401", mr.getPo0401());}
			if(mr.getPo0500()!=null){parameters.put("pO0500", mr.getPo0500());}
			if(mr.getPo0501()!=null){parameters.put("pO0501", mr.getPo0501());}
			if(mr.getPo0600()!=null){parameters.put("pO0600", mr.getPo0600());}
			if(mr.getPo0601()!=null){parameters.put("pO0601", mr.getPo0601());}
			if(mr.getPo0700()!=null){parameters.put("pO0700", mr.getPo0700());}
			if(mr.getPo0701()!=null){parameters.put("pO0701", mr.getPo0701());}
			if(mr.getPo0800()!=null){parameters.put("pO0800", mr.getPo0800());}
			if(mr.getPo0801()!=null){parameters.put("pO0801", mr.getPo0801());}
			if(mr.getPo0900()!=null){parameters.put("pO0900", mr.getPo0900());}
			if(mr.getPo0901()!=null){parameters.put("pO0901", mr.getPo0901());}
			if(mr.getPo1000()!=null){parameters.put("pO1000", mr.getPo1000());}
			if(mr.getPo1001()!=null){parameters.put("pO1001", mr.getPo1001());}
			if(mr.getPo1100()!=null){parameters.put("pO1100", mr.getPo1100());}
			if(mr.getPo1200()!=null){parameters.put("pO1200", mr.getPo1200());}
			if(mr.getPo1201()!=null){parameters.put("pO1201", mr.getPo1201());}
			if(mr.getPo1300()!=null){parameters.put("pO1300", mr.getPo1300());}
			if(mr.getPo1301()!=null){parameters.put("pO1301", mr.getPo1301());}
			if(mr.getPo1400()!=null){parameters.put("pO1400", mr.getPo1400());}
			if(mr.getPo1500()!=null){parameters.put("pO1500", mr.getPo1500());}
			if(mr.getPo1501()!=null){parameters.put("pO1501", mr.getPo1501());}
			if(mr.getPo0201()!=null){parameters.put("pO0201", mr.getPo0201());}
			sql = "UPDATE DRGS.MR_OPERATION T SET "
			+ (mr.getPo0100()!=null?("T.PO0100=:pO0100, "):("T.PO0100 = null, "))
			+ (mr.getPo0101()!=null?("T.PO0101=:pO0101, "):("T.PO0101 = null, "))
			+ (mr.getPoType()!=null?("T.POTYPE=:pOType, "):("T.POTYPE = null, "))
			+ (mr.getPo0200()!=null?("T.PO0200=:pO0200, "):("T.PO0200 = null, "))
			+ (mr.getPo0300()!=null?("T.PO0300=:pO0300, "):("T.PO0300 = null, "))
			+ (mr.getPo0301()!=null?("T.PO0301=:pO0301, "):("T.PO0301 = null, "))
			+ (mr.getPo0400()!=null?("T.PO0400=:pO0400, "):("T.PO0400 = null, "))
			+ (mr.getPo0401()!=null?("T.PO0401=:pO0401, "):("T.PO0401 = null, "))
			+ (mr.getPo0500()!=null?("T.PO0500=:pO0500, "):("T.PO0500 = null, "))
			+ (mr.getPo0501()!=null?("T.PO0501=:pO0501, "):("T.PO0501 = null, "))
			+ (mr.getPo0600()!=null?("T.PO0600=:pO0600, "):("T.PO0600 = null, "))
			+ (mr.getPo0601()!=null?("T.PO0601=:pO0601, "):("T.PO0601 = null, "))
			+ (mr.getPo0700()!=null?("T.PO0700=:pO0700, "):("T.PO0700 = null, "))
			+ (mr.getPo0701()!=null?("T.PO0701=:pO0701, "):("T.PO0701 = null, "))
			+ (mr.getPo0800()!=null?("T.PO0800=:pO0800, "):("T.PO0800 = null, "))
			+ (mr.getPo0801()!=null?("T.PO0801=:pO0801, "):("T.PO0801 = null, "))
			+ (mr.getPo0900()!=null?("T.PO0900=:pO0900, "):("T.PO0900 = null, "))
			+ (mr.getPo0901()!=null?("T.PO0901=:pO0901, "):("T.PO0901 = null, "))
			+ (mr.getPo1000()!=null?("T.PO1000=:pO1000, "):("T.PO1000 = null, "))
			+ (mr.getPo1001()!=null?("T.PO1001=:pO1001, "):("T.PO1001 = null, "))
			+ (mr.getPo1100()!=null?("T.PO1100=:pO1100, "):("T.PO1100 = null, "))
			+ (mr.getPo1200()!=null?("T.PO1200=:pO1200, "):("T.PO1200 = null, "))
			+ (mr.getPo1201()!=null?("T.PO1201=:pO1201, "):("T.PO1201 = null, "))
			+ (mr.getPo1300()!=null?("T.PO1300=:pO1300, "):("T.PO1300 = null, "))
			+ (mr.getPo1301()!=null?("T.PO1301=:pO1301, "):("T.PO1301 = null, "))
			+ (mr.getPo1400()!=null?("T.PO1400=:pO1400, "):("T.PO1400 = null, "))
			+ (mr.getPo1500()!=null?("T.PO1500=:pO1500, "):("T.PO1500 = null, "))
			+ (mr.getPo1501()!=null?("T.PO1501=:pO1501, "):("T.PO1501 = null, "))
			+ (mr.getPo0201()!=null?("T.PO0201=:pO0201 "):("T.PO0201 = null  "))
			+ "WHERE T.PMAININDEX=:pMainIndex AND T.POINDEX=:pOIndex";
			if(mr.getPo0101()!=null) {
				getRepository().createSqlQuery(sql).setParameters(parameters).executeUpdate();
			}
		}else{
			if(mr.getPo0101()!=null) {
				mr.save();
			}
		}
	}
	public void createMrExpense(MrExpense mr){
		Map<String, Object> parameters = new HashMap<>();
		parameters.put("pMainIndex", mr.getPmainIndex());
		parameters.put("peIndex", mr.getPeIndex());
		String sql = "SELECT 1 FROM DRGS.MR_EXPENSE T WHERE T.PMAININDEX=:pMainIndex AND T.PEINDEX=:peIndex";
		List<Object> list = getRepository().createSqlQuery(sql).setParameters(parameters).list();
		if(list.size()>0){
			if(mr.getPe0200()!=null){parameters.put("pE0200", mr.getPe0200());}
			if(mr.getPe0101()!=null){parameters.put("pE0101", mr.getPe0101());}
			sql = "UPDATE DRGS.MR_EXPENSE T SET "
			+ (mr.getPe0200()!=null?("T.PE0200=:pE0200, "):("T.PE0200 = null, "))
			+ (mr.getPe0101()!=null?("T.PE0101=:pE0101 "):("T.PE0101 = null "))
			+ " WHERE T.PMAININDEX=:pMainIndex AND T.PEINDEX=:peIndex";
			if(mr.getPe0101()!=null) {
				getRepository().createSqlQuery(sql).setParameters(parameters).executeUpdate();
			}
		}else{
			if(mr.getPe0101()!=null) {
				mr.save();
			}
		}
	}
	/**  
	 * @Description:查询病案号是否存在于数据库中
	 * @author shaozhiyuan 
	 * @date 2018年5月16日  
	 * @version V3.1.0  
	 */  
	@Override
	public Boolean findAbnomalGroupCase(String obj) {
		Map<String, Object> parameters = new HashMap<>();
		parameters.put("pMainIndex", obj==null?"":obj.toString().trim());
		String sql = "SELECT 1 FROM DRGS.Mr_Baseinfo T WHERE T.P00050000=:pMainIndex ";
		List<Object> list = getRepository().createSqlQuery(sql).setParameters(parameters).list();
		if(list.size()>0){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 
	 * @Description: 获取分组异常数据列表详细信息 
	 * @author shaozhiyuan 
	 * @date 2018年5月16日  
	 * @version V3.1.0
	 */
	@Override
	public List<Map<String, Object>> findAbnomalGroupCaseList(String inCaseNumberStr) {
		StringBuffer sql=new StringBuffer();
		String sqlResult = "SELECT COUNT(A.PMAININDEX) FROM DRGS.MR_OPERATION A WHERE A.PO1400 ='1' and A.POTYPE='M'";
		String caseOperationCount = jdbcTemplateObj.queryForObject(sqlResult.toString(), String.class);
		sql.append("select a.pmainindex PMAININDEX, b.P00050000 MRNUMBER, P.VER_CODE VERCODE, \n");
		sql.append("case when P.pardrg_code is not null then P.pardrg_code else to_char(log.notin_reason) end  newgroup, \n");
		sql.append("case when P.pardrg_code is not null then P.pardrg_code else to_char(P.NOTIN_REASON) end  oldgroup, \n");
	    sql.append("log.gl_j01||','||log.gl_j02||','||log.gl_j03||','||log.gl_j04||','||log.gl_j05||','||log.gl_j06||','||log.gl_j07||',' \n");
	    sql.append("||log.gl_j08||','||log.gl_j08_1||','||log.gl_j09||','||log.gl_j10_1||','||log.gl_j10_2||','||log.gl_j10_3||','||log.gl_j10_4||',' \n");
	    sql.append("||log.gl_j10_4_0||','||log.gl_j10_5||','||log.gl_j10_6||','||log.gl_j11 newlog, \n");
	    sql.append("p.log_info oldlog, b.P00070001 sex, b.P00090000 age, b.P00090002 newbornday, b.P00120000 newbornweight, \n");
	    sql.append("c.P90120201 ventihour , a.P00320000 indays, a.P00800000 costamount, a.P00620001 lyfs, \n");
	    sql.append("case when  matchd.bj_icd_code is not null then matchd.bj_icd_code else d1.PD0101 end mdiagcode, \n");
	    sql.append("case when  matchd.bj_icd_desc is not null then matchd.bj_icd_desc else d1.PD0100 end mdiagdesc, \n");
	    sql.append("d2.ODIAGAICD, d2.ODIAGADESC ,d2.ODIAGBICD, d2.ODIAGBDESC,d2.ODIAGCICD, d2.ODIAGCDESC,d2.ODIAGDICD, d2.ODIAGDDESC,d2.ODIAGEICD, d2.ODIAGEDESC, \n");
	    sql.append("d2.ODIAGFICD, d2.ODIAGFDESC ,d2.ODIAGGICD, d2.ODIAGGDESC,d2.ODIAGHICD, d2.ODIAGHDESC,d2.ODIAGIICD, d2.ODIAGIDESC,d2.ODIAGJICD, d2.ODIAGJDESC, \n");
	    sql.append("case when  matcho.bj_icd_code is not null then matcho.bj_icd_code else o1.PO0101 end mopercode, \n");
	    sql.append("case when  matcho.bj_icd_desc is not null then matcho.bj_icd_desc else o1.PO0100 end moperdesc, \n");
	    sql.append("o2.DoperAICD, o2.DoperADESC ,o2.DoperBICD, o2.DoperBDESC,o2.DoperCICD, o2.DoperCDESC,o2.DoperDICD, o2.DoperDDESC,o2.DoperEICD, o2.DoperEDESC, \n");
	    sql.append("o2.DoperFICD, o2.DoperFDESC ,o2.DoperGICD, o2.DoperGDESC,o2.DoperHICD, o2.DoperHDESC,o2.DoperIICD, o2.DoperIDESC,o2.DoperJICD, o2.DoperJDESC \n");
	    if(Integer.parseInt(caseOperationCount==null?"0":caseOperationCount.toString().trim())>1){
	    sql.append(",case when  matchh.bj_icd_code is not null then matchh.bj_icd_code else o3.PO0101 end mhandlercode, \n");
	    sql.append(" case when  matchh.bj_icd_desc is not null then matchh.bj_icd_desc else o3.PO0100 end mhandlerdesc, \n");
	    sql.append("o4.DhandleAICD, o4.DhandleADESC ,o4.DhandleBICD, o4.DhandleBDESC,o4.DhandleCICD, o4.DhandleCDESC,o4.DhandleDICD, o4.DhandleDDESC,o4.DhandleEICD, o4.DhandleEDESC, \n");
	    sql.append("o4.DhandleFICD, o4.DhandleFDESC ,o4.DhandleGICD, o4.DhandleGDESC,o4.DhandleHICD, o4.DhandleHDESC,o4.DhandleIICD, o4.DhandleIDESC,o4.DhandleJICD, o4.DhandleJDESC \n");
	    }
	    sql.append("from drgs.mr_ipinfo a left join drgs.mr_baseinfo b on a.pmainindex=b.pmainindex \n");
		sql.append("left join drgs.mr_appendpage c on a.pmainindex=c.pmainindex \n");
		sql.append("left join drgs.t_patientdrg p on a.pmainindex=p.parid \n"); 
		sql.append("left join drgs.mr_diagnose d1 on d1.pmainindex=a.pmainindex and d1.pdtype='M' \n");
		sql.append("LEFT JOIN drgs.T_ICDMATCH_RESULT_DIA matchd on  d1.pd0101=matchd.hosp_icd_code and matchd.icdmat_type='1'  \n");
		sql.append("left join( select diag.pmainindex pmainindex, \n");
		sql.append("max(decode(diag.pdindex, 1, diag.pd0101, NULL)) AS ODIAGAICD,  max(decode(diag.pdindex, 1,diag.pd0100, NULL)) AS ODIAGADESC ,\n");
		sql.append("max(decode(diag.pdindex, 2, diag.pd0101, NULL)) AS ODIAGBICD,  max(decode(diag.pdindex, 2,diag.pd0100, NULL)) AS ODIAGBDESC, \n");
		sql.append("max(decode(diag.pdindex, 3, diag.pd0101, NULL)) AS ODIAGCICD,  max(decode(diag.pdindex, 3,diag.pd0100, NULL)) AS ODIAGCDESC, \n");
		sql.append("max(decode(diag.pdindex, 4, diag.pd0101, NULL)) AS ODIAGDICD,  max(decode(diag.pdindex, 4,diag.pd0100, NULL)) AS ODIAGDDESC, \n");
		sql.append("max(decode(diag.pdindex, 5, diag.pd0101, NULL)) AS ODIAGEICD,  max(decode(diag.pdindex, 5,diag.pd0100, NULL)) AS ODIAGEDESC, \n");
		sql.append("max(decode(diag.pdindex, 6, diag.pd0101, NULL)) AS ODIAGFICD,  max(decode(diag.pdindex, 6,diag.pd0100, NULL)) AS ODIAGFDESC, \n");
		sql.append("max(decode(diag.pdindex, 7, diag.pd0101, NULL)) AS ODIAGGICD,  max(decode(diag.pdindex, 7,diag.pd0100, NULL)) AS ODIAGGDESC, \n");
		sql.append("max(decode(diag.pdindex, 8, diag.pd0101, NULL)) AS ODIAGHICD,  max(decode(diag.pdindex, 8,diag.pd0100, NULL)) AS ODIAGHDESC, \n");
		sql.append("max(decode(diag.pdindex, 9, diag.pd0101, NULL)) AS ODIAGIICD,  max(decode(diag.pdindex, 9,diag.pd0100, NULL)) AS ODIAGIDESC, \n");
		sql.append("max(decode(diag.pdindex, 10, diag.pd0101, NULL)) AS ODIAGJICD,  max(decode(diag.pdindex, 10,diag.pd0100, NULL)) AS ODIAGJDESC \n");
		sql.append("from(  \n");
		sql.append("select a.pmainindex,a.pdindex, case when  b.bj_icd_desc is not null then b.bj_icd_desc else a.pd0100 end pd0100,  \n");
		sql.append("case when  b.bj_icd_code is not null then b.bj_icd_code else a.pd0101 end pd0101 \n");
		sql.append("from drgs.MR_DIAGNOSE a  left join drgs.T_ICDMATCH_RESULT_DIA b on a.pd0101=b.hosp_icd_code and b.icdmat_type='1' where pdtype='O' \n");
		sql.append(") diag group by diag.pmainindex \n");
		sql.append(")d2 on d2.pmainindex=a.pmainindex left join drgs.mr_operation o1 \n");
		if(Integer.parseInt(caseOperationCount==null?"0":caseOperationCount.toString().trim())>1){
			 sql.append("on o1.pmainindex=a.pmainindex and o1.potype='M' AND o1.po1400='1' \n");
			 sql.append(" LEFT JOIN drgs.T_ICDMATCH_RESULT_OPER matcho on o1.PO0101=matcho.hosp_icd_code and matcho.icdmat_type='1' \n");
			 sql.append(" left join ( select  oper.pmainindex pmainindex,  \n");
		}else{
			 sql.append(" on o1.pmainindex=a.pmainindex and o1.potype='M'  \n");
			 sql.append(" LEFT JOIN drgs.T_ICDMATCH_RESULT_OPER matcho on o1.PO0101=matcho.hosp_icd_code and matcho.icdmat_type='1' \n");
			 sql.append(" left join ( select  oper.pmainindex pmainindex,  \n");
		}
		sql.append("max(decode(oper.poindex, 1, oper.po0101, NULL)) AS DoperAICD,  max(decode(oper.poindex, 1,oper.po0100, NULL)) AS DoperADESC , \n");
		sql.append("max(decode(oper.poindex, 2, oper.po0101, NULL)) AS DoperBICD,  max(decode(oper.poindex, 2,oper.po0100, NULL)) AS DoperBDESC, \n");
		sql.append("max(decode(oper.poindex, 3, oper.po0101, NULL)) AS DoperCICD,  max(decode(oper.poindex, 3,oper.po0100, NULL)) AS DoperCDESC, \n");
		sql.append("max(decode(oper.poindex, 4, oper.po0101, NULL)) AS DoperDICD,  max(decode(oper.poindex, 4,oper.po0100, NULL)) AS DoperDDESC, \n");
		sql.append("max(decode(oper.poindex, 5, oper.po0101, NULL)) AS DoperEICD,  max(decode(oper.poindex, 5,oper.po0100, NULL)) AS DoperEDESC, \n");
		sql.append("max(decode(oper.poindex, 6, oper.po0101, NULL)) AS DoperFICD,  max(decode(oper.poindex, 6,oper.po0100, NULL)) AS DoperFDESC, \n");
		sql.append("max(decode(oper.poindex, 7, oper.po0101, NULL)) AS DoperGICD,  max(decode(oper.poindex, 7,oper.po0100, NULL)) AS DoperGDESC, \n");
		sql.append("max(decode(oper.poindex, 8, oper.po0101, NULL)) AS DoperHICD,  max(decode(oper.poindex, 8,oper.po0100, NULL)) AS DoperHDESC, \n");
		sql.append("max(decode(oper.poindex, 9, oper.po0101, NULL)) AS DoperIICD,  max(decode(oper.poindex, 9,oper.po0100, NULL)) AS DoperIDESC, \n");
		sql.append("max(decode(oper.poindex, 10, oper.po0101, NULL)) AS DoperJICD,  max(decode(oper.poindex, 10,oper.po0100, NULL)) AS DoperJDESC \n");
		sql.append("from(  \n");
		if(Integer.parseInt(caseOperationCount==null?"0":caseOperationCount.toString().trim())>1){
			sql.append("select a.pmainindex,a.poindex, case when  b.bj_icd_desc is not null then b.bj_icd_desc else a.PO0100 end PO0100, \n");
			sql.append("case when  b.bj_icd_code is not null then b.bj_icd_code else a.PO0101 end PO0101  from drgs.MR_OPERATION a \n");
			sql.append("left join drgs.T_ICDMATCH_RESULT_OPER b on a.PO0101=b.hosp_icd_code and b.icdmat_type='1' where POTYPE='O' AND a.po1400='1' \n");
		}else{
			sql.append("select a.pmainindex,a.poindex, case when  b.bj_icd_desc is not null then b.bj_icd_desc else a.PO0100 end PO0100, \n");
			sql.append("case when  b.bj_icd_code is not null then b.bj_icd_code else a.PO0101 end PO0101  from drgs.MR_OPERATION a \n");
			sql.append("left join drgs.T_ICDMATCH_RESULT_OPER b on a.PO0101=b.hosp_icd_code and b.icdmat_type='1' where POTYPE='O' \n");
		}
		sql.append(" ) oper group by oper.pmainindex )o2 on o2.pmainindex=a.pmainindex   \n");
		if(Integer.parseInt(caseOperationCount==null?"0":caseOperationCount.toString().trim())>1){
		sql.append("left join drgs.mr_operation o3 on o3.pmainindex=a.pmainindex and o3.potype='M' and o3.po1400='0' \n");
		sql.append("LEFT JOIN drgs.T_ICDMATCH_RESULT_OPER matchh on o3.PO0101=matchh.hosp_icd_code and matchh.icdmat_type='1' \n");
		sql.append("left join ( select  oper.pmainindex pmainindex, \n");
		sql.append("max(decode(oper.poindex, 1, oper.po0101, NULL)) AS DhandleAICD,  max(decode(oper.poindex, 1,oper.po0100, NULL)) AS DhandleADESC ,\n");
		sql.append("max(decode(oper.poindex, 2, oper.po0101, NULL)) AS DhandleBICD,  max(decode(oper.poindex, 2,oper.po0100, NULL)) AS DhandleBDESC,\n");
		sql.append("max(decode(oper.poindex, 3, oper.po0101, NULL)) AS DhandleCICD,  max(decode(oper.poindex, 3,oper.po0100, NULL)) AS DhandleCDESC,\n");
		sql.append("max(decode(oper.poindex, 4, oper.po0101, NULL)) AS DhandleDICD,  max(decode(oper.poindex, 4,oper.po0100, NULL)) AS DhandleDDESC,\n");
		sql.append("max(decode(oper.poindex, 5, oper.po0101, NULL)) AS DhandleEICD,  max(decode(oper.poindex, 5,oper.po0100, NULL)) AS DhandleEDESC,\n");
		sql.append("max(decode(oper.poindex, 6, oper.po0101, NULL)) AS DhandleFICD,  max(decode(oper.poindex, 6,oper.po0100, NULL)) AS DhandleFDESC,\n");
		sql.append("max(decode(oper.poindex, 7, oper.po0101, NULL)) AS DhandleGICD,  max(decode(oper.poindex, 7,oper.po0100, NULL)) AS DhandleGDESC,\n");
		sql.append("max(decode(oper.poindex, 8, oper.po0101, NULL)) AS DhandleHICD,  max(decode(oper.poindex, 8,oper.po0100, NULL)) AS DhandleHDESC,\n");
		sql.append("max(decode(oper.poindex, 9, oper.po0101, NULL)) AS DhandleIICD,  max(decode(oper.poindex, 9,oper.po0100, NULL)) AS DhandleIDESC,\n");
		sql.append("max(decode(oper.poindex, 10, oper.po0101, NULL)) AS DhandleJICD,  max(decode(oper.poindex, 10,oper.po0100, NULL)) AS DhandleJDESC \n");
		sql.append("from(  \n");
		sql.append("select a.pmainindex,a.poindex, case when  b.bj_icd_desc is not null then b.bj_icd_desc else a.PO0100 end PO0100, \n");
		sql.append("case when  b.bj_icd_code is not null then b.bj_icd_code else a.PO0101 end PO0101  from drgs.MR_OPERATION a \n");
		sql.append("left join drgs.T_ICDMATCH_RESULT_OPER b on a.PO0101=b.hosp_icd_code and b.icdmat_type='1' where POTYPE='O' AND a.po1400='0' \n");
		sql.append(" ) oper group by oper.pmainindex \n");
		sql.append(") o4 on o4.pmainindex=a.pmainindex \n");
		}
		sql.append("left join drgs.t_groupinglog log on a.pmainindex=log.mr_adm  where b.P00050000 in("+inCaseNumberStr+") \n");
		List<Map<String,Object>> list =jdbcTemplateObj.queryForList(sql.toString()) ; 
		return list;
	}
	/**  
	 * @Description: 区分是否手术或操作
	 * @author shaozhiyuan 
	 * @date 2018年5月17日  
	 * @version V3.1.0  
	 */  
	@Override
	public Boolean checkIsOper() {
		String sqlResult = "SELECT COUNT(A.PMAININDEX) FROM DRGS.MR_OPERATION A WHERE A.PO1400 ='1' and A.POTYPE='M'";
		String caseOperationCount = jdbcTemplateObj.queryForObject(sqlResult.toString(), String.class);
		if(Integer.parseInt(caseOperationCount==null?"0":caseOperationCount.toString().trim())>1){
			return true;
		}else{
			return false;
		}
	}
	
	@Override
	public int saveConfirmFlag(String datefrom, String dateto){
		String sql = "select count(1) from DRGs.MR_IPINFO WHERE to_char(P00290000,'yyyy-mm-dd') BETWEEN '"+datefrom+"' AND '"+dateto+"'";
		int count = jdbcTemplateObj.queryForObject(sql, Integer.class);
		if(count > 0){
			sql = "";
			sql = "UPDATE DRGs.MR_IPINFO SET CONFIRMFLAG=1 WHERE to_char(P00290000,'yyyy-mm-dd') BETWEEN '"+datefrom+"' AND '"+dateto+"' ";
			jdbcTemplateObj.execute(sql);
		}
		return count;
	}
}
